<template>
	<view class="content">
		<commonTitle title="首页" subTitle="子标题"></commonTitle>
		<!-- <image class="logo" src="/static/logo.png"></image> -->
		<!-- 绑定点击事件函数的方式 v-on:click=""-->
		<view class="text-area" v-on:click="onClick">
			<text class="title">{{title}}</text>
		</view>
		<!-- v-bind 绑定的写法 -->
		<button @click="onClickNum">
			<text class="num">num: {{num}}</text>
		</button>
		
		<!-- 绑定style -->
		<view class="box" :style="{background: bgcolor}" @click="onClickBg"></view>
		<!-- 绑定class -->
		<view class="block" :class="{myactive: state}" @click="onClickBlock"></view>
		<!-- 绑定class 三元表达式写法 -->
		<view class="block" :class="state ? 'myactive' : ''"></view>
		
		<view class="nav">
			<view class="item" :class="navIndex==index ? 'active' : ''" v-for="(item, index) in navArr" :key="item.id" @click="clickNav(index)">{{item.title}}</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: 'Hello uni-app',
				num: 1,
				bgcolor: 'blue',
				state: false,
				navArr: [
					{id: 1, title: "首页"},
					{id: 2, title: "介绍"},
					{id: 3, title: "教程"},
					{id: 4, title: "组件"}
				],
				navIndex: 0
			}
		},
		onLoad() {

		},
		methods: {
			onClick: function() {
				this.title = 'hello, what news'
			},
			
			onClickNum() {
				this.num++
			},
			
			onClickBg() {
				let randomNum = Math.random()
				let color = "#" + String(randomNum).substring(3, 9)
				console.log(color, randomNum)
				this.bgcolor = color
			},
			
			onClickBlock() {
				this.state = !this.state
			},
			
			clickNav(index) {
				console.log(index)
				this.navIndex = index
			}

		}
	}
</script>

<style lang="scss">
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
	
	.box {
		height: 200rpx;
		width: 200rpx;
		background: pink;
	}
	
	.block {
		height: 300rpx;
		width: 300rpx;
		background: black;
	}
	
	.myactive {
		width: 400rpx;
		background: hotpink;
		border-radius: 20rpx;
	}
	
	.nav {
		display: flex;
		flex-direction: row;
		width: 800rpx;
		justify-content: space-between;
		align-items: center;
		.item {
			flex: 1;
			line-height: 90rpx;
			background: #cccccc;
			text-align: center;
			&.active {
				background: #1AA034;
				color: #ffffff;
			}
		}
		// .item.active {
			
		// }
		
	}
</style>
